package com.streambolics.worseminton.data;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.streambolics.data.PersistentObject;
import com.streambolics.data.Person;

/**
 * A list of Worseminton objects owned by a single user.
 * 
 * @author Sauron
 * 
 * @param <T>
 *            The type of owned object.
 */

public abstract class WorsemintonOwnedObjectList<T extends PersistentObject> extends WorsemintonObjectList<T>
{
    private long ownerId;

    @Override
    protected void bindQueryVariables (Query q)
    {
        super.bindQueryVariables (q);
        q.declareParameters ("long p_ownerId");
    }

    protected void delayLoad (PersistenceManager aDatabase, Person aOwner)
    {
        super.delayLoad (aDatabase);
        ownerId = aOwner.getId ();
    }

    @Override
    protected Object executeQuery (Query aQuery)
    {
        return aQuery.execute (ownerId);
    }

    protected long getOwnerId ()
    {
        return ownerId;
    }

    @Override
    protected String standardQueryText (Class<T> aClass)
    {
        return super.standardQueryText (aClass) + " where ownerId == p_ownerId";
    }

}
